var express = require('express');
var router = express.Router();

const { getOrders, deleteOrders, getOrdersById, deleteOrdersById
    , addOrder, searchById, changeOrdersState } = require('../service/ordersService');
/* GET home page. */
/*1.管理员 */
//获取订单列表
router.get('/getOrders', async function (req, res, next) {
    const orders = req.query;
    const result = await getOrders(orders);
    res.send(result);
});

//删除
router.post('/deleteOrders', async function (req, res, next) {
    const _id = req.body;
    const result = await deleteOrders(_id);
    res.send(result);
});

/*出租方 */
//获取订单列表
router.get('/getOrdersById', async function (req, res, next) {
    const orders = req.query;
    const result = await getOrdersById(orders);
    res.send(result);
});

//删除
router.post('/deleteOrdersById', async function (req, res, next) {
    const _id = req.body;
    const result = await deleteOrdersById(_id);
    res.send(result);
});


// 新增订单
router.post('/addOrder', async function (req, res, next) {
    const code = req.body;
    const result = await addOrder(code);
    res.send(result);
});


//通过出租方id查找数据
router.post('/searchById', async function (req, res, next) {
    const id = req.body;
    const result = await searchById(id);
    res.send(result);
});


//还车位
router.post('/changeOrdersState', async function (req, res, next) {
    const id = req.body;
    const data = await changeOrdersState(id);
    res.send(data);
});


module.exports = router;
